package com.alpha.eceasy.mall.mapper;

import com.alpha.eceasy.extension.BaseSqlMapper;
import com.alpha.eceasy.mall.api.vo.MallCommodityVO;

import com.alpha.eceasy.mall.api.entity.MallCommodity;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import jakarta.validation.constraints.NotNull;
import java.util.List;

@Mapper
public interface MallCommodityMapper extends BaseSqlMapper<MallCommodity> {
	@Select("select c.*, cc.id as mallCommodityCategoryIdTwo, cc.name as mallCommodityCategoryNameTwo, cd.icon as icon, cd.label as label, cd.type as type, " +
			"cdl.cover as cover, cdl.content as content, mcc.id as mallCommodityCategoryIdOne, mcc.name as mallCommodityCategoryNameOne " +
			"from mall_commodity c " +
			"left join mall_commodity_category_asso cca on c.commodity_dict_id = cca.commodity_dict_id " +
			"left join mall_commodity_category cc on cca.commodity_category_id = cc.id " +
			"left join mall_commodity_category mcc on mcc.id = cc.parent_id " +
			"left join mall_commodity_dict cd on cd.id = c.commodity_dict_id " +
			"left join mall_commodity_detail cdl on c.commodity_dict_id = cdl.commodity_dict_id ${ew.customSqlSegment}")
	IPage<MallCommodityVO> getMallCommodityPage(Page<MallCommodity> page, @NotNull @Param(Constants.WRAPPER) Wrapper wrapper);

	@Select("select c.*, cc.id as mallCommodityCategoryIdTwo, cc.name as mallCommodityCategoryNameTwo, cd.icon as icon, cd.label as label, cd.type as type, " +
			"cdl.cover as cover, cdl.content as content, mcc.id as mallCommodityCategoryIdOne, mcc.name as mallCommodityCategoryNameOne " +
			"from mall_commodity c " +
			"left join mall_commodity_category_asso cca on c.commodity_dict_id = cca.commodity_dict_id " +
			"left join mall_commodity_category cc on cca.commodity_category_id = cc.id " +
			"left join mall_commodity_category mcc on mcc.id = cc.parent_id " +
			"left join mall_commodity_dict cd on cd.id = c.commodity_dict_id " +
			"left join mall_commodity_detail cdl on c.commodity_dict_id = cdl.commodity_dict_id ${ew.customSqlSegment}")
	List<MallCommodityVO> getMallCommodityList(@NotNull @Param(Constants.WRAPPER) Wrapper wrapper);

	@Select("select c.*, cc.id as mallCommodityCategoryIdTwo, cc.name as mallCommodityCategoryNameTwo, " +
			"cd.icon as icon, cd.label as label, cd.type as type, cd.approval, " +
			"cdl.cover as cover, cdl.content as content,cdl.drug_explain as drugExplain, " +
			"mcc.id as mallCommodityCategoryIdOne, mcc.name as mallCommodityCategoryNameOne " +
			"from mall_commodity c " +
			"left join mall_commodity_category_asso cca on c.commodity_dict_id = cca.commodity_dict_id " +
			"left join mall_commodity_category cc on cca.commodity_category_id = cc.id " +
			"left join mall_commodity_category mcc on mcc.id = cc.parent_id " +
			"left join mall_commodity_dict cd on cd.id = c.commodity_dict_id " +
			"left join mall_commodity_detail cdl on c.commodity_dict_id = cdl.commodity_dict_id where c.id = #{id} and c.deleted = 0")
    MallCommodityVO getMallCommodity(@Param("id") Long id);
}
